<html><head> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
<meta name="keywords" content="wtf2l f2l oll pll trainer rubiks cube timer main page cubing speedcubing speedsolving fast fridrich method cfop"> 
<meta name="description" content="WTF2L cube algs"> 
<title>WTF2L Cube Algs</title> 
<title>F2L Trainer</title>
<style type="text/css">
<!-- 
.hover { border: none; border-width: thin thin thin thin;} 
--> 
</style>
<script language="JavaScript" src="jquery-1.3.2.min.js"></script>
<script language="JavaScript"> 
var imgsize = 60; //题目图片大小
var excount = 18; //题目数量
// 246  240  230 F6 F0 E6
var imgurl = "http://cube.crider.co.uk/visualcube.php?size=" + imgsize + "&fmt=png&bg=EEE";
//var imgurl = "img/visualcube.php@size=" + imgsize + "&fmt=png&bg=EEE";
// 白底
var scheme = "yrbwog";
// 黄底
//var scheme = "wobyrg";
// 蓝底
//var scheme = "gwrbyo";
// 绿底
//var scheme = "bwogyr";
// 红底
//var scheme = "obwrgy";
// 橙底
//var scheme = "rgwoby";
var view = "";
var ms = 9999;
var state = 2;
var displayidx = 0;
var imgready = 0;
var imgload = 0;
var subjectindex = 0;
var addms = 0; // 罚秒
var corner_pos = 3; //角块出于所有位置
var global_r, global_r1, global_r2; 
var stoped = false; 
$(function(){
	$("#startstopbutton").click(startstop);
	$("#resetbutton").click(swreset);
	// init subject
	for(var i = 0; i < excount; i++) {
		$("#subject").append("<img id=\"img"+i+"\" src=\"\" width="+imgsize+" height="+imgsize+"/>");
		if((i+1)%6 == 0)
			$("#subject").append("<br/>");
	}
	$("#subject").css({visibility:"hidden"});
	$("#subject img").each(function(i){
		$(this).load(imgonload);
	});
	$("#pos").change(function(){
		corner_pos = this.value;
	});
	displaytime();
	showanswer();
});
function exporturl() {
	var aa = [
		"yrbwog",
		"wobyrg",
		"gwrbyo",
		"bwogyr",
		"obwrgy",
		"rgwoby"
	];
	var cube = new Object();
	for(i in aa) {
		cube.sch = aa[i];
		cube.pzl=1;
		cube.bg="t";
		cube.size=30;
		cube.fd="nrfdlb";
		cube.r="y45x0";
		debug(imgurl+cube2str(cube)+"<br/>");
		cube.r="y135x0";
		debug(imgurl+cube2str(cube)+"<br/>");
		cube.r="y-135x0";
		debug(imgurl+cube2str(cube)+"<br/>");
		cube.r="y-45x0";
		debug(imgurl+cube2str(cube)+"<br/>");
		cube.fd="nnnnnn";
		debug(imgurl+cube2str(cube)+"<br/>");
	}
	var s;
	for(i in aa) {
		scheme = aa[i];
	for(global_r1 = 0; global_r1 < 2; global_r1++)
	for(global_r2 = 0; global_r2 < 4; global_r2++)
	for(var i = 0; i < 3; i++)
	for(var j = 0; j < 2; j++)
	{
		if(global_r1 == 0)
		{
			for(global_r = 0; global_r < 3; global_r++) {
				s = getcube(i,j);
				debug(imgurl+s[0]+"<br/>");
			}
		} 
		else
		{
			s = getcube(i,j);
			debug(imgurl+s[0]+"<br/>");
		}
	}
	}
}
function imgonload() {
	if(state == 2) {
		imgload++; 
		if(imgload == excount) subjectready();
	}
}
function debug(str)
{
	document.getElementById("debug").innerHTML+=str;
}
function debug2(str)
{
	document.getElementById("debug").innerHTML=str;
}
function debugimg(img)
{
	document.getElementById("debug").innerHTML+="<img src=\""+img+"\"/>";
}
function getcorner(c) {
	var fd0 = "uuuuuuuuurrrrrrrrrfffffffffdddddddddlllllllllbbbbbbbbb";
	var fd1 = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn";
	var clevel = {
		"u":1,"d":0,
		"r":2,"l":0,
		"f":4,"b":0
	};
	var cface = new Array(
		[27+6,36+6,45+8],//dlb
		[0,45+2,36],//ubl
		[27+2,45+6,9+8],//dbr
		[2,9+2,45],//urb
		[27,18+6,36+8],//dfl
		[6,36+2,18],//ulf
		[27+8,9+6,18+8],//drf
		[8,18+2,9]//ufr
	);
	c = c.toLowerCase();
	var cindex = clevel[c.substr(0,1)] | clevel[c.substr(1,1)] | clevel[c.substr(2,1)];
	var ucorners = new Array("ufr","ulf","ubl","urb");
	var corners = new Array("drf","dfl","dlb","dbr");
	var r1 = Math.floor(Math.random() * 4);// 几率1:3
	var r2 = Math.floor(Math.random() * 4);
	if(global_r1 != undefined) r1 = global_r1;
	if(global_r2 != undefined) r2 = global_r2;
	if(r1 == 1) {
		var corner = ucorners[r2];
	} else {
		var corner = corners[r2];
	}
	var a = fd1.split("");
	var r;
	if(corner.substr(0,1) == "u") {
		if(cindex == 4 || cindex == 6) {
			r = 0;
		} else if(cindex == 7 || cindex == 3) {
			r = 1;
		} else {
			r = 2;
		}
	} else {
		if(global_r != undefined) 
			r = global_r;
		else
			r = Math.floor(Math.random() * 3);
	}
	for(var i = 0; i < 3; i++) {
		a[cface[cindex][i]] = corner.substr(r,1);
		r++;
		r %= 3;
	}
	fd1 = a.join("");
	var answer = r2;
	if(r1 == 1) answer = 4;
	return [fd1, answer];
}
function getcube(r,r2) {
	var cube = new Object();
	cube.sch = scheme;
	cube.view = view;
	var pos0 = new Array("FDL", "FDR");
	var pos1 = new Array("FUL", "FUR");
	var pos2 = new Array("BUL", "BUR");
	if(r == undefined) {
		if(corner_pos == 0 || corner_pos == 1 || corner_pos == 2)
			r = corner_pos;
		else 
			r = Math.floor(Math.random() * 3);
	}
	if(r2 == undefined)
		r2 = Math.floor(Math.random() * 2);
	var ret;
	if(r == 0) 
	{
		ret = getcorner(pos0[r2]);
		if(r2 == 1) cube.r = "y30x-10";
		else cube.r = "y-30x-10";
	} 
	else if(r == 1) 
	{
		ret = getcorner(pos1[r2]);
		if(r2 == 0) cube.r = "y30x-34";
		else cube.r = "y-30x-34";
	}
	else 
	{
		ret = getcorner(pos2[r2]);
		if(r2 == 1) cube.r = "y30x-34z-30";
		else cube.r = "y-30x-34z30";
	}
	cube.fd = ret[0];
	answer = ret[1];
	return [cube2str(cube),answer];
}
function cube2str(cube) {
	var s = "";
	for(key in cube) {
		s += "&"+key+"="+cube[key];
	}
	return s;
}
function changesubject() {
	imgload = 0;
	subjectindex = 0;
	addms = 0;
	$("#subject").css({visibility:"hidden"});
	$("#subject img").each(function(i){
		var s;
		s = getcube();
		this.src = imgurl + s[0];
		this.alt = s[1];
		$(this).fadeTo("fast", 1);
	});
}
function showanswer() {
	$("#option").append("<img id=\"ans0\" alt=0 src=\"\" />&nbsp;&nbsp;<img id=\"ans1\" alt=1 src=\"\" /><br/><img id=\"ans4\" alt=4 src=\"\" /><br/><img id=\"ans2\" alt=2 src=\"\" />&nbsp;&nbsp;<img id=\"ans3\" alt=3 src=\"\" />");
	var cube = new Object();
	cube.sch = scheme;
	cube.pzl=1;
	cube.bg="t";
	cube.size=30;
	cube.fd="nrfdlb";
	cube.r="y45x0";
	$("#ans0").attr("src",imgurl+cube2str(cube));
	cube.r="y135x0";
	$("#ans3").attr("src",imgurl+cube2str(cube));
	cube.r="y-135x0";
	$("#ans2").attr("src",imgurl+cube2str(cube));
	cube.r="y-45x0";
	$("#ans1").attr("src",imgurl+cube2str(cube));
	cube.fd="nnnnnn";
	$("#ans4").attr("src",imgurl+cube2str(cube));
	$("#option img").each(function(i){
		$(this).click(function(){
			if(state != 1) return;
			if(this.alt != $("#img"+subjectindex).attr("alt")) {
				addms += 5000;
				$("#img"+subjectindex).fadeTo("fast",0.5);
			} else {
				$("#img"+subjectindex).fadeTo("fast",0.1);
			}
			subjectindex++;
			if(subjectindex == excount) {
				startstop();
			}
		});
		$(this).hover(function(){
			$(this).addClass("hover");   
		},function(){
			$(this).removeClass("hover");  
		});  
	});
}
function displaytime()
{
   setTimeout("displaytime();", 10);
   if (state == 1)
   {
      now = new Date();
      ms = now.getTime() - then.getTime();
      displayidx++;
      displayidx %= 6;
      if(displayidx == 0)
      drawtime(ms);
   }
}
function drawtime(diff)
{	
	diff += addms;
	totalsec=Math.floor(diff/1000);
	sec=totalsec%60;
	if(sec<10)
	{
		secdis="0"+sec;
	}
	else
	{
		secdis=sec;
	}
	min=(totalsec-sec)/60;

	if (min<10)
	{
		mindis="0"+min;
	}
	else
	{
		mindis=min;
	}

	subsec=Math.floor((diff%1000)/10);

	if (subsec<10)
	{
		subsecdis="0"+subsec;
	}
	else 
	{
		subsecdis=subsec;
	}
	nowSeconds=mindis+":"+secdis+"."+subsecdis;
	document.getElementById("watch").innerHTML=nowSeconds;
}
function subjectready()
{
	state = 0;
	$("#startstopbutton").val("Start");
}
function swreset()
{
	state = 2;
	$("#startstopbutton").val("Begin");
	ms = 0;
	drawtime(ms);
}
function startstop()
{
	// ready
	if (state == 0)
	{
		state = 1; //计时开始
		then = new Date();
		$("#startstopbutton").val("Stop");
		$("#subject").css({visibility:"visible"});
		then.setTime(then.getTime() - ms);
	}
	else if (state == 1) // 计时中
	{
		state = 2;
		now = new Date();
		ms = now.getTime() - then.getTime();
		$("#startstopbutton").val("Confirm?");
		drawtime(ms);
	}
	else if (state == 2)
	{
		now = new Date();
		ms = 0;
		$("#startstopbutton").val("Waiting...");
		changesubject();
		drawtime(ms);
	}
}
</script> 
</head>
<body>
<center> 
<div id="debug"></div>
<h2>F2L Trainer</h2> 
</center> 
<center> 
<div id="subject"></div>
<form name="stpw"> 
<input size="150" value="Begin"  id="startstopbutton" type="BUTTON"> 
<input name="reset" value="Cancel"  id="resetbutton" type="BUTTON"> 
<div id="option"></div>
<div id="watch" style="filter:shadraw(x=1,y=1,color=black);position:relative;width: 359px; height: 80px ; font-size:48pt; font-family:Arial; font-weight:bold; color:navy; text-align:center" >00:00.00</div> 
<p></p> 
角块出现位置:<select id="pos" size="1" > 
	 <option value="0">FDL,FDR</option> 
	 <option value="1">FUL,FUR</option> 
	 <option value="2">BUL,BUR</option> 
	 <option selected="selected" value="3">全部</option> 
</select>
</form> 
<br> 
<p>Images generated by <a href="http://cube.crider.co.uk/visualcube.php">VisualCube</a></p> 
<p><a href="mailto:oyd_admin@163.com">Email me</a> for comments or suggestions</p> 
</center> 
</body></html> 
